package demo2;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: DELL
 * Date: 2023-08-07
 * Time: 15:28
 */


class Singleton {

    // 提供一个变量
    private static Singleton instance = new Singleton();

    // 提供一个私有无参构造方法
    private Singleton() {

    }

    // 提供一个 get 方法供外部获取使用
    public static Singleton getInstance() {
        return instance;
    }
}

public class Thread3 {
    public static void main(String[] args) {
        Singleton singleton = Singleton.getInstance();
        Singleton singleton1 = Singleton.getInstance();
        System.out.println(singleton.equals(singleton1));
    }
}
